<template>
  <div>
    <!--卡片-->
    <el-card class="box-card">
      <!-- 搜索与添加区域 -->
      <el-button v-hasPermi="['admin','oms:omsorderreturnapply:add']" type="primary" small class="addBtn" style="margin:10px" size="mini" icon="el-icon-plus" @click="addDialogVisible = true">新增
      </el-button>
      <!--表格-->
      <el-table :data="listForm" stripe border style="width: 100%">
        <el-table-column prop="id" header-align="center" align="center" label="id" />
        <el-table-column prop="orderId" header-align="center" align="center" label="order_id" />
        <el-table-column prop="skuId" header-align="center" align="center" label="退货商品id" />
        <el-table-column prop="orderSn" header-align="center" align="center" label="订单编号" />
        <el-table-column prop="createTime" header-align="center" align="center" label="申请时间" />
        <el-table-column prop="memberUsername" header-align="center" align="center" label="会员用户名" />
        <el-table-column prop="returnAmount" header-align="center" align="center" label="退款金额" />
        <el-table-column prop="returnName" header-align="center" align="center" label="退货人姓名" />
        <el-table-column prop="returnPhone" header-align="center" align="center" label="退货人电话" />
        <el-table-column prop="status" header-align="center" align="center" label="申请状态[0->待处理；1->退货中；2->已完成；3->已拒绝]" />
        <el-table-column prop="handleTime" header-align="center" align="center" label="处理时间" />
        <el-table-column prop="skuImg" header-align="center" align="center" label="商品图片" />
        <el-table-column prop="skuName" header-align="center" align="center" label="商品名称" />
        <el-table-column prop="skuBrand" header-align="center" align="center" label="商品品牌" />
        <el-table-column prop="skuAttrsVals" header-align="center" align="center" label="商品销售属性(JSON)" />
        <el-table-column prop="skuCount" header-align="center" align="center" label="退货数量" />
        <el-table-column prop="skuPrice" header-align="center" align="center" label="商品单价" />
        <el-table-column prop="skuRealPrice" header-align="center" align="center" label="商品实际支付单价" />
        <el-table-column prop="reason" header-align="center" align="center" label="原因" />
        <el-table-column prop="description述" header-align="center" align="center" label="描述" />
        <el-table-column prop="descPics" header-align="center" align="center" label="凭证图片，以逗号隔开" />
        <el-table-column prop="handleNote" header-align="center" align="center" label="处理备注" />
        <el-table-column prop="handleMan" header-align="center" align="center" label="处理人员" />
        <el-table-column prop="receiveMan" header-align="center" align="center" label="收货人" />
        <el-table-column prop="receiveTime" header-align="center" align="center" label="收货时间" />
        <el-table-column prop="receiveNote" header-align="center" align="center" label="收货备注" />
        <el-table-column prop="receivePhone" header-align="center" align="center" label="收货电话" />
        <el-table-column prop="companyAddress" header-align="center" align="center" label="公司收货地址" />
        <!--操作-->
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-tooltip :enterable="false" effect="dark" content="编辑" placement="top">
              <el-button v-hasPermi="['admin','oms:omsorderreturnapply:edit']" type="success" icon="el-icon-edit" size="mini" @click="editBtn(scope.row.id)" />
            </el-tooltip>
            <el-tooltip :enterable="false" effect="dark" content="删除" placement="top">
              <el-button v-hasPermi="['admin','oms:omsorderreturnapply:del']" type="danger" icon="el-icon-delete" size="mini" @click="delBtn(scope.row.id)" />
            </el-tooltip>
          </template>
        </el-table-column>
      </el-table>

      <!--分页区域-->
      <el-pagination
        background
        :current-page="pageNumber"
        :page-sizes="[1, 2, 5, 10]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      />

    </el-card>

    <!--添加对话框-->
    <el-dialog title="添加" :close-on-click-modal="false" :visible.sync="addDialogVisible" width="580px" @close="addHandleClose">
      <span>
        <el-form ref="addFormRef" :model="addForm" :rules="addFormRules" label-width="100px">
          <el-form-item label="id" prop="id">
            <el-input v-model="addForm.id" />
          </el-form-item>
          <el-form-item label="order_id" prop="orderId">
            <el-input v-model="addForm.orderId" />
          </el-form-item>
          <el-form-item label="退货商品id" prop="skuId">
            <el-input v-model="addForm.skuId" />
          </el-form-item>
          <el-form-item label="订单编号" prop="orderSn">
            <el-input v-model="addForm.orderSn" />
          </el-form-item>
          <el-form-item label="申请时间" prop="createTime">
            <el-input v-model="addForm.createTime" />
          </el-form-item>
          <el-form-item label="会员用户名" prop="memberUsername">
            <el-input v-model="addForm.memberUsername" />
          </el-form-item>
          <el-form-item label="退款金额" prop="returnAmount">
            <el-input v-model="addForm.returnAmount" />
          </el-form-item>
          <el-form-item label="退货人姓名" prop="returnName">
            <el-input v-model="addForm.returnName" />
          </el-form-item>
          <el-form-item label="退货人电话" prop="returnPhone">
            <el-input v-model="addForm.returnPhone" />
          </el-form-item>
          <el-form-item label="申请状态[0->待处理；1->退货中；2->已完成；3->已拒绝]" prop="status">
            <el-input v-model="addForm.status" />
          </el-form-item>
          <el-form-item label="处理时间" prop="handleTime">
            <el-input v-model="addForm.handleTime" />
          </el-form-item>
          <el-form-item label="商品图片" prop="skuImg">
            <el-input v-model="addForm.skuImg" />
          </el-form-item>
          <el-form-item label="商品名称" prop="skuName">
            <el-input v-model="addForm.skuName" />
          </el-form-item>
          <el-form-item label="商品品牌" prop="skuBrand">
            <el-input v-model="addForm.skuBrand" />
          </el-form-item>
          <el-form-item label="商品销售属性(JSON)" prop="skuAttrsVals">
            <el-input v-model="addForm.skuAttrsVals" />
          </el-form-item>
          <el-form-item label="退货数量" prop="skuCount">
            <el-input v-model="addForm.skuCount" />
          </el-form-item>
          <el-form-item label="商品单价" prop="skuPrice">
            <el-input v-model="addForm.skuPrice" />
          </el-form-item>
          <el-form-item label="商品实际支付单价" prop="skuRealPrice">
            <el-input v-model="addForm.skuRealPrice" />
          </el-form-item>
          <el-form-item label="原因" prop="reason">
            <el-input v-model="addForm.reason" />
          </el-form-item>
          <el-form-item label="描述" prop="description述">
            <el-input v-model="addForm.description述" />
          </el-form-item>
          <el-form-item label="凭证图片，以逗号隔开" prop="descPics">
            <el-input v-model="addForm.descPics" />
          </el-form-item>
          <el-form-item label="处理备注" prop="handleNote">
            <el-input v-model="addForm.handleNote" />
          </el-form-item>
          <el-form-item label="处理人员" prop="handleMan">
            <el-input v-model="addForm.handleMan" />
          </el-form-item>
          <el-form-item label="收货人" prop="receiveMan">
            <el-input v-model="addForm.receiveMan" />
          </el-form-item>
          <el-form-item label="收货时间" prop="receiveTime">
            <el-input v-model="addForm.receiveTime" />
          </el-form-item>
          <el-form-item label="收货备注" prop="receiveNote">
            <el-input v-model="addForm.receiveNote" />
          </el-form-item>
          <el-form-item label="收货电话" prop="receivePhone">
            <el-input v-model="addForm.receivePhone" />
          </el-form-item>
          <el-form-item label="公司收货地址" prop="companyAddress">
            <el-input v-model="addForm.companyAddress" />
          </el-form-item>
        </el-form>
        <!--底部区域-->
      </span>
      <span slot="footer" class="dialog-footer">
        <el-button @click="addDialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="addClick">确 定</el-button>
      </span>
    </el-dialog>

    <!--编辑对话框-->
    <el-dialog title="编辑" :close-on-click-modal="false" :visible.sync="editDialogVisible" width="580px" @close="editHandleClose">
      <span>
        <el-form ref="editFormRef" :model="editForm" label-width="100px">
          <el-form-item label="id" prop="id">
            <el-input v-model="editForm.id" />
          </el-form-item>
          <el-form-item label="order_id" prop="orderId">
            <el-input v-model="editForm.orderId" />
          </el-form-item>
          <el-form-item label="退货商品id" prop="skuId">
            <el-input v-model="editForm.skuId" />
          </el-form-item>
          <el-form-item label="订单编号" prop="orderSn">
            <el-input v-model="editForm.orderSn" />
          </el-form-item>
          <el-form-item label="申请时间" prop="createTime">
            <el-input v-model="editForm.createTime" />
          </el-form-item>
          <el-form-item label="会员用户名" prop="memberUsername">
            <el-input v-model="editForm.memberUsername" />
          </el-form-item>
          <el-form-item label="退款金额" prop="returnAmount">
            <el-input v-model="editForm.returnAmount" />
          </el-form-item>
          <el-form-item label="退货人姓名" prop="returnName">
            <el-input v-model="editForm.returnName" />
          </el-form-item>
          <el-form-item label="退货人电话" prop="returnPhone">
            <el-input v-model="editForm.returnPhone" />
          </el-form-item>
          <el-form-item label="申请状态[0->待处理；1->退货中；2->已完成；3->已拒绝]" prop="status">
            <el-input v-model="editForm.status" />
          </el-form-item>
          <el-form-item label="处理时间" prop="handleTime">
            <el-input v-model="editForm.handleTime" />
          </el-form-item>
          <el-form-item label="商品图片" prop="skuImg">
            <el-input v-model="editForm.skuImg" />
          </el-form-item>
          <el-form-item label="商品名称" prop="skuName">
            <el-input v-model="editForm.skuName" />
          </el-form-item>
          <el-form-item label="商品品牌" prop="skuBrand">
            <el-input v-model="editForm.skuBrand" />
          </el-form-item>
          <el-form-item label="商品销售属性(JSON)" prop="skuAttrsVals">
            <el-input v-model="editForm.skuAttrsVals" />
          </el-form-item>
          <el-form-item label="退货数量" prop="skuCount">
            <el-input v-model="editForm.skuCount" />
          </el-form-item>
          <el-form-item label="商品单价" prop="skuPrice">
            <el-input v-model="editForm.skuPrice" />
          </el-form-item>
          <el-form-item label="商品实际支付单价" prop="skuRealPrice">
            <el-input v-model="editForm.skuRealPrice" />
          </el-form-item>
          <el-form-item label="原因" prop="reason">
            <el-input v-model="editForm.reason" />
          </el-form-item>
          <el-form-item label="描述" prop="description述">
            <el-input v-model="editForm.description述" />
          </el-form-item>
          <el-form-item label="凭证图片，以逗号隔开" prop="descPics">
            <el-input v-model="editForm.descPics" />
          </el-form-item>
          <el-form-item label="处理备注" prop="handleNote">
            <el-input v-model="editForm.handleNote" />
          </el-form-item>
          <el-form-item label="处理人员" prop="handleMan">
            <el-input v-model="editForm.handleMan" />
          </el-form-item>
          <el-form-item label="收货人" prop="receiveMan">
            <el-input v-model="editForm.receiveMan" />
          </el-form-item>
          <el-form-item label="收货时间" prop="receiveTime">
            <el-input v-model="editForm.receiveTime" />
          </el-form-item>
          <el-form-item label="收货备注" prop="receiveNote">
            <el-input v-model="editForm.receiveNote" />
          </el-form-item>
          <el-form-item label="收货电话" prop="receivePhone">
            <el-input v-model="editForm.receivePhone" />
          </el-form-item>
          <el-form-item label="公司收货地址" prop="companyAddress">
            <el-input v-model="editForm.companyAddress" />
          </el-form-item>
        </el-form>
        <!--底部区域-->
      </span>
      <span slot="footer" class="dialog-footer">
        <el-button @click="editDialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="editClick">确 定</el-button>
      </span>
    </el-dialog>

  </div>
</template>

<script>
import { add, edit, del, getOmsOrderReturnApply, listOmsOrderReturnApply } from '@/api/order/omsorderreturnapply'

export default {
  name: 'Returns',
  data() {
    return {
      addDialogVisible: false,
      editDialogVisible: false,
      pageNumber: 1,
      pageSize: 10,
      total: 0,
      listForm: [],
      addForm: {
        id: '',
        orderId: '',
        skuId: '',
        orderSn: '',
        createTime: '',
        memberUsername: '',
        returnAmount: '',
        returnName: '',
        returnPhone: '',
        status: '',
        handleTime: '',
        skuImg: '',
        skuName: '',
        skuBrand: '',
        skuAttrsVals: '',
        skuCount: '',
        skuPrice: '',
        skuRealPrice: '',
        reason: '',
        description述: '',
        descPics: '',
        handleNote: '',
        handleMan: '',
        receiveMan: '',
        receiveTime: '',
        receiveNote: '',
        receivePhone: '',
        companyAddress: ''
      },
      editForm: {},
      addFormRules: {
        id: [
          { required: true, message: '请输入id', trigger: 'blur' }
        ],
        orderId: [
          { required: true, message: '请输入order_id', trigger: 'blur' }
        ],
        skuId: [
          { required: true, message: '请输入退货商品id', trigger: 'blur' }
        ],
        orderSn: [
          { required: true, message: '请输入订单编号', trigger: 'blur' }
        ],
        createTime: [
          { required: true, message: '请输入申请时间', trigger: 'blur' }
        ],
        memberUsername: [
          { required: true, message: '请输入会员用户名', trigger: 'blur' }
        ],
        returnAmount: [
          { required: true, message: '请输入退款金额', trigger: 'blur' }
        ],
        returnName: [
          { required: true, message: '请输入退货人姓名', trigger: 'blur' }
        ],
        returnPhone: [
          { required: true, message: '请输入退货人电话', trigger: 'blur' }
        ],
        status: [
          { required: true, message: '请输入申请状态[0->待处理；1->退货中；2->已完成；3->已拒绝]', trigger: 'blur' }
        ],
        handleTime: [
          { required: true, message: '请输入处理时间', trigger: 'blur' }
        ],
        skuImg: [
          { required: true, message: '请输入商品图片', trigger: 'blur' }
        ],
        skuName: [
          { required: true, message: '请输入商品名称', trigger: 'blur' }
        ],
        skuBrand: [
          { required: true, message: '请输入商品品牌', trigger: 'blur' }
        ],
        skuAttrsVals: [
          { required: true, message: '请输入商品销售属性(JSON)', trigger: 'blur' }
        ],
        skuCount: [
          { required: true, message: '请输入退货数量', trigger: 'blur' }
        ],
        skuPrice: [
          { required: true, message: '请输入商品单价', trigger: 'blur' }
        ],
        skuRealPrice: [
          { required: true, message: '请输入商品实际支付单价', trigger: 'blur' }
        ],
        reason: [
          { required: true, message: '请输入原因', trigger: 'blur' }
        ],
        description述: [
          { required: true, message: '请输入描述', trigger: 'blur' }
        ],
        descPics: [
          { required: true, message: '请输入凭证图片，以逗号隔开', trigger: 'blur' }
        ],
        handleNote: [
          { required: true, message: '请输入处理备注', trigger: 'blur' }
        ],
        handleMan: [
          { required: true, message: '请输入处理人员', trigger: 'blur' }
        ],
        receiveMan: [
          { required: true, message: '请输入收货人', trigger: 'blur' }
        ],
        receiveTime: [
          { required: true, message: '请输入收货时间', trigger: 'blur' }
        ],
        receiveNote: [
          { required: true, message: '请输入收货备注', trigger: 'blur' }
        ],
        receivePhone: [
          { required: true, message: '请输入收货电话', trigger: 'blur' }
        ],
        companyAddress: [
          { required: true, message: '请输入公司收货地址', trigger: 'blur' }
        ]
      }
    }
  },
  created() {
    // 初始化列表
    this.initListOmsOrderReturnApply()
  },

  methods: {
    // 添加按钮
    addBtn() {
      this.addDialogVisible = true
    },

    // 确认添加
    addClick() {
      this.$refs.addFormRef.validate(valid => {
        if (!valid) return
        add(this.addForm).then(res => {
          if (res.code === 20000) {
            this.$message.success(res.message)
            // 刷新数据
            this.initListOmsOrderReturnApply()
          }
          // 关闭对话框
          this.addDialogVisible = false
        })
      })
    },

    // 编辑按钮
    editBtn(id) {
      this.editDialogVisible = true
      getOmsOrderReturnApply(id).then(res => {
        if (res.code === 20000) {
          this.editForm = res.data
        }
      })
    },

    // 确认编辑
    editClick() {
      this.$refs.editFormRef.validate(valid => {
        if (!valid) return
        edit(this.editForm).then(res => {
          if (res.code === 20000) {
            this.$message.success(res.message)
            // 刷新数据
            this.initListOmsOrderReturnApply()
          }
          // 关闭对话框
          this.editDialogVisible = false
        })
      })
    },

    // 删除按钮
    delBtn(id) {
      this.$confirm('此操作将永久删除该用户, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        // 确认操作
        del(id).then(res => {
          if (res.code === 20000) {
            this.$message.success(res.message)
            // 刷新数据
            this.initListOmsOrderReturnApply()
          }
        })
      })
    },

    // 监听当前页的事件
    handleCurrentChange(pageIndex) {
      this.pageNumber = pageIndex
      this.initListOmsOrderReturnApply()
    },

    // 监听当前页的条数事件
    handleSizeChange(pageSize) {
      this.pageSize = pageSize
      this.initListOmsOrderReturnApply()
    },

    // 监听添加对话框的关闭事件，重置表单内容
    addHandleClose() {
      this.$refs.addFormRef.resetFields()
    },

    // 监听编辑对话框的关闭事件,重置表单内容
    editHandleClose() {
      this.$refs.editFormRef.resetFields()
    },

    // 初始化数据
    initListOmsOrderReturnApply() {
      const params = {
        pageNum: this.pageNumber,
        pageSize: this.pageSize
      }
      listOmsOrderReturnApply(params).then(res => {
        this.listForm = res.data.records
        this.total = res.data.total
        this.pageNum = res.data.current
      })
    }
  }
}
</script>

<style scoped>
</style>
